home *** CD-ROM | disk | FTP | other *** search
- /*
- ******************************************************************************
- * NCSA ImageTool 1.1 beta
- * Thu Sep 20 16:58:25 CDT 1990
- *
- * NCSA ImageTool 1.1 beta source code and documentation are in the public
- * domain.
- * Specifically, we give to the public domain all rights for future licensing
- * of the source code, all resale rights, and all publishing rights.
- *
- * We ask, but do not require, that the following message be included in all
- * derived works:
- *
- * Portions developed at the National Center for Supercomputing Applications at
- * the University of Illinois at Urbana-Champaign.
- *
- * THE UNIVERSITY OF ILLINOIS GIVES NO WARRANTY, EXPRESSED OR IMPLIED, FOR THE
- * SOFTWARE AND/OR DOCUMENTATION PROVIDED, INCLUDING, WITHOUT LIMITATION,
- * WARRANTY OF MERCHANTABILITY AND WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE
- *
- ******************************************************************************
- */
- /* cat > headers/new.h << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* new.h: header for new.c file */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- #include "all.h"
- #include "newext.h"
-
- /* EOF */
- /* cat > src+obj/new/check_filetype.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* check_filetype: check whether a file is a file or a */
- /* directory is a directory. */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "all.h" */
- /* #include "newext.h" */
-
- int
- check_filetype (path, type)
- /* returns: 0 - correct type
- -1 - wrong type */
- char *path;
- /* input: must be full legal pathname */
- int type;
- /* input: TYPE_DIR - directory
- TYPE_FILE - file */
- {
- /* check if wrong type */
- if (type == TYPE_DIR)
- { /* directory */
- sprintf (wkstr, "csh -fc \"test -d '%s'\"", path);
- if (check_system (wkstr)) /* 0 exit status means true */
- return (-1);
- }
- else if (type == TYPE_FILE)
- { /* file */
- sprintf (wkstr, "csh -fc \"test -f '%s'\"", path);
- /* printf */
- /* msg_write (wkstr); */
- if (check_system (wkstr)) /* 0 exit status means true */
- return (-1);
- }
- return (0);
- }
- /* EOF */
- /* cat > src+obj/new/check_system.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* check_system: send a command to the system () C */
- /* library function and return success or */
- /* failure. Standard error is redirected */
- /* to the bit bucket. */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "all.h" */
- /* #include "newext.h" */
-
- int
- check_system (s)
- /* returns 0 = success
- -1 = failure */
- char *s;
- /* input: command string */
- {
- /* Implementation note(s):
- 1. Use /dev/null as the bit bucket.
- */
-
- int newd;
-
- /* stderr (fd = 2) should go to /dev/null */
- newd = dup (2);
- close (2);
-
- (void) open ("/dev/null", O_WRONLY); /* should not fail - opens on 2 */
-
- if (system (s))
- {
- (void) dup2 (newd, 2);
- close (newd);
- return (-1);
- }
- else
- { /* 0 exit means true */
- (void) dup2 (newd, 2);
- close (newd);
- return (0);
- }
- }
- /* EOF */
- /* cat > src+obj/new/first_word.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* first_word: get first word in a string. White space */
- /* is space or tab. */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "all.h" */
-
- char *
- first_word (s, len)
- /* returns: pointer to first character of word */
- char *s;
- /* input: string to locate first word */
- int *len;
- /* returns: length of word in characters */
- {
- register int c;
-
- /* strip off any leading white space */
- *len = 0;
- while ((c = *s++) != NULL)
- if (c != ' ' && c != '\t')
- {
- (*len)++;
- break;
- }
-
- /* scan the word */
- while ((c = *s++) != NULL)
- if (c == ' ' || c == '\t')
- break;
- else
- (*len)++;
-
- return (s - *len - 1);
- }
- /* EOF */
- /* cat > src+obj/new/free_list.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* free_list: free storage associate with a char ** */
- /* variable from wildcard. */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "all.h" */
- /* #include "newext.h" */
-
- int
- free_list (var)
- char **var;
- {
- int i;
-
- /* if there are no files - var points to one location with
- a NULL pointer */
- if (var[0] == NULL)
- return;
- else
- {
- i = 0;
- while (var[i] != NULL)
- free (var[i++]);
- }
- free (var);
- return;
- }
- /* EOF */
- /* cat > src+obj/new/get_abspathname.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* get_abspathname: resolve a path to an absolute */
- /* pathname. The intended type, file */
- /* or directory must be provided. */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "all.h" */
- /* #include "newext.h" */
-
- int
- get_abspathname (fn, maxfnlen, type)
- /* returns:
- error - 0 = no error
- 1 = no such type
- 2 = wrong type
- 3 = no pathname
- 4 = multiple pathnames
- 5 = ambiguous type - wildcard
- 6 = syntax - wildcard (error 1)
- 7 = memory allocation -
- wildcard (error 2) -
- internal
- 8 = not enough string space in
- argument - internal
- 9 = pathname for current
- directory failed - internal
- 10 = change directory failed
- - internal
- 11 = pathname for new directory
- failed - internal
- 12 = NULL pointer to fn -
- internal
- 13 = nonpositive maxfnlen
- value - internal
- 14 = bad type value - internal */
- char *fn;
- /* input: relative or absolute pathname that
- would be parsed correctly by the
- C-shell. Multiple pathnames result
- in an error.
- returns: (no error) the absolute pathname
- fully resolved provided the length
- is not greater than maxfnlen - 1.
- (error) orginal string is
- returned. */
- int maxfnlen;
- /* input: maximum length of final path + 1 of
- filename storage for fn. */
- int type;
- /* input: TYPE_DIR - directory
- TYPE_FILE - file */
- {
- int nt, err, fnlen, fflen, cdlen;
- char **path;
- char *fpart, *pwd, *new_pwd;
-
- char *getcwd (); /* standard C library */
-
- /* bad arguments */
- if (fn == NULL)
- return (12);
- else if (maxfnlen < 1)
- return (13);
- else if (type < 0 || type > 1)
- return (14);
-
- if ((nt = word_count (fn)) != 1)
- { /* incorrect number of "tokens" */
- if (nt == 0)
- return (3); /* no pathname */
- else
- return (4); /* too many potential paths */
- }
-
- path = wildcard (fn, &err);
-
- /* printf */
- /* sprintf (wkstr, "path = %s", path[0]);
- msg_write (wkstr); */
- if (err != 0)
- { /* wildcard error */
- if (err == 1)
- return (6); /* syntax */
- else
- return (7); /* memory allocation */
- }
- if (path[0] == NULL) /* no match */
- return (1);
- else if (path[1] != NULL) /* ambiguous filename */
- {
- (void) free_list (path);
- return (5);
- }
- if ((fnlen = strlen (path[0])) > maxfnlen - 1) /* not enought string space */
- {
- (void) free_list (path);
- return (8);
- }
-
- /* build full pathname */
- pwd = getcwd ((char *) NULL, MAXNAMELEN + 1); /* must free before return */
- if (pwd == NULL) /* size too small or internal error */
- {
- (void) free_list (path);
- return (9);
- }
- cdlen = strlen (pwd);
- if (type == TYPE_FILE) /* file */
- {
- fpart = strrchr (path[0], '/'); /* find last / */
- if (fpart == NULL) /* no directory part - use current directory */
- { /* add 1 for / */
- if ((cdlen + 1 + fnlen) > maxfnlen - 1) /* not enough string space */
- {
- (void) free_list (path);
- free (pwd);
- return (8);
- }
- sprintf (wkstr2, "%s/%s", pwd, path[0]);
- /* printf */
- /* msg_write (wkstr2); */
- if (check_filetype (wkstr2, type))
- {
- (void) free_list (path);
- free (pwd);
- return (2);
- }
- strcpy (fn, wkstr2);
- (void) free_list (path);
- free (pwd);
- return (0);
- }
- fflen = strlen (fpart) - 1;
- *fpart = '\0'; /* temporary make path[0] point just to the directory part */
- }
- if (chdir (path[0])) /* if problem then internal error */
- {
- (void) free_list (path);
- free (pwd);
- return (10);
- }
- new_pwd = getcwd ((char *) NULL, MAXNAMELEN + 1); /* must free before return */
- if (new_pwd == NULL) /* size too small or internal error */
- {
- (void) free_list (path);
- free (pwd);
- return (11);
- }
- cdlen = strlen (new_pwd);
- if (type == TYPE_DIR)
- { /* directory */
- strcpy (wkstr2, new_pwd);
- if (check_filetype (wkstr2, type))
- {
- (void) free_list (path);
- free (pwd);
- free (new_pwd);
- return (2);
- }
- strcpy (fn, new_pwd);
- }
- else if (type == TYPE_FILE) /* file */
- { /* add 1 for / */
- if ((cdlen + 1 + fflen) > maxfnlen - 1)
- { /* not enough string space */
- (void) free_list (path);
- (void) chdir (pwd); /* should not error */
- free (pwd);
- free (new_pwd);
- return (8);
- }
- sprintf (wkstr2, "%s/%s", new_pwd, fpart + 1);
- if (check_filetype (wkstr2, type))
- {
- (void) free_list (path);
- free (pwd);
- free (new_pwd);
- return (2);
- }
- strcpy (fn, wkstr2);
- }
-
- (void) free_list (path);
- (void) chdir (pwd); /* should not error */
- free (pwd);
- free (new_pwd);
- return (0);
- }
- /* EOF */
- /* cat > src+obj/new/pixrect_pad.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* pixrect_pad: horizontal padding in bytes for memory */
- /* pixrect. */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "all.h" */
- /* #include "newext.h" */
-
- int
- pixrect_pad (xdim)
- /* returns: the number of bytes of
- horizontal padding */
- int xdim;
- /* input: horizontal dimension of memory
- pixrect */
- {
- /*
- BUG: mpr_linebytes () is wrong on Sun-3 and Sun-4. It computes padding
- to 16 bits not 32 bits which mem_create uses. Decided not to use it.
- Can't tell when it works!
- */
- #if sun == sparc || sun == mc68020 || sun == mc68030
- return ((xdim % 4 == 0) ? 0 : 4 - xdim % 4);
- #else
- return ((xdim % 2 == 0) ? 0 : 2 - xdim % 2);
- #endif
- }
- /* EOF */
- /* cat > src+obj/new/strip_wspace.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* strip_wspace: strip off leading and trailing white */
- /* space. */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "all.h" */
- /* #include "newext.h" */
-
- int
- strip_wspace (s)
- /* returns the length */
- char *s;
- /* input: string to strip
- returns: stripped string with s[0]
- the first non-whitespace
- character */
- {
- /* Implementation note(s):
- 1. Assumes that s is not NULL and the string is NULL
- terminated.
- */
-
- register int i, j, k;
-
- /* strip off trailing white space */
- if ((i = strlen (s)) == 0)
- return (0);
- while (--i >= 0 && (s[i] == ' ' || s[i] == '\t'));
- s[++i] = '\0';
- if (i == 0)
- return (0);
-
- /* strip off leading white space */
- if (s[0] != ' ' && s[0] != '\t')
- return (i);
- for (j = 0; s[j] == ' ' || s[j] == '\t'; j++);
- for (k = 0; k < i - j; k++)
- s[k] = s[k + j];
- s[i - j] = '\0';
- return ((i - j));
- }
- /* EOF */
- /* cat > src+obj/new/tty_write.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* tty_write: write message to tty subwindow */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "all.h" */
- /* #include "newext.h" */
-
- void
- tty_write (msg)
- char *msg;
- {
-
- ttysw_input (ttysw, msg, strlen (msg));
- }
- /* EOF */
- /* cat > src+obj/new/window_corner.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* window_corner: get corner coordinates of frame */
- /* PIXWIN */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "all.h" */
- /* #include "newext.h" */
-
- int
- window_corner (frame, vside, hside, x_corner, y_corner)
- /* returns: 0 = success
- -1 = failure */
- Frame frame;
- /* input: frame to get corner corrdinates of */
- enum rect_vertical vside;
- /* input: which vertical side for corner */
- enum rect_horizontal hside;
- /* input: which horizontal side for corner */
- int *x_corner;
- /* returns: x value of PIXWIN corner if no error */
- int *y_corner;
- /* returns: y value of PIXWIN corner if no error */
- {
- Rect *rect_frame;
-
- if (frame == NULL)
- return (-1);
- rect_frame = (Rect *) window_get (frame, WIN_RECT);
-
- *x_corner = rect_frame->r_left;
- *y_corner = rect_frame->r_top;
- switch (vside)
- {
- case LEFT:
- switch (hside)
- {
- case TOP:
- break;
- case BOTTOM:
- *y_corner += rect_frame->r_height;
- break;
- default:
- return (-1);
- }
- break;
- case RIGHT:
- *x_corner += rect_frame->r_width;
- switch (hside)
- {
- case TOP:
- break;
- case BOTTOM:
- *y_corner += rect_frame->r_height;
- break;
- default:
- return (-1);
- }
- break;
- default:
- return (-1);
- }
- return (0);
- }
- /* EOF */
- /* cat > src+obj/new/word_count.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* word_count: number of words in string. White space */
- /* is space or tab. */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "all.h" */
- /* #include "newext.h" */
-
- int
- word_count (s)
- /* returns: the number of words in
- the input string */
- char *s;
- {
- register int count, word, c;
-
- count = 0;
- word = 0;
- while ((c = *s++) != NULL)
- if (c == ' ' || c == '\t') /* white space */
- word = 0;
- else if (!word)
- { /* not white space */
- word = 1;
- count++;
- }
- return (count);
- }
- /* EOF */
-